﻿using System.Collections.Generic;
using Microsoft.Win32;
//using EnvDTE;
//using EnvDTE80;

namespace VisualStudioSensor {
    /// <summary>
    /// Window registry read write utility. All properties are assumed located under 
    /// "LocalMachine\SOFTWARE\Hackystat\VisualStudioSensor".
    /// </summary>
    internal class WindowsRegistryUtil {
        private const string REGISTRY_HOME = @"SOFTWARE\Hackystat\VisualStudioSensor";
        internal const string JAVA_HOME = "JavaHome";
        internal const string SENSOR_SHELL_JAR = "SensorShellJar";

        /// <summary>
        /// Reads property value from windows registry.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        /// <returns>The property value, or null if the property cannot be found.</returns>
        internal static string ReadProperty(string name) {
            string targetValue = null;
            RegistryKey key = Registry.CurrentUser.OpenSubKey(REGISTRY_HOME);
            if (key != null) {
                targetValue = (string)key.GetValue(name);
                key.Close();
            }
            return targetValue;
        }

        /// <summary>
        /// Writes or overwrites the property value in windows registry.
        /// </summary>
        /// <param name="name">Property name.</param>
        /// <param name="targetValue">Property value.</param>
        internal static void WriteProperty(string name, string targetValue) {
            RegistryKey key = Registry.CurrentUser.CreateSubKey(REGISTRY_HOME);
            key.SetValue(name, targetValue);
            key.Close();
        }
    }
}
